package com.chen.blue.service.candidate;


import com.chen.blue.dictionary.CommonDict;
import com.chen.blue.service.security.SecurityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2024/5/10.
 */
@SuppressWarnings("all")
@Slf4j
public class CandidateInfoService {

    /**
     * 记录操作用户
     *
     * @param data
     * @param <T>
     */
    public static <T> void setCreator(List<T> data) {

        if (Objects.isNull(data) || data.isEmpty()) {
            return;
        }

        try {
            for (T t : data) {
                BeanUtils.setProperty(t, CommonDict.CANDIDATE_NAME_CREATOR, SecurityService.currentUserName());
            }
        } catch (IllegalAccessException e) {
            log.error(e.getMessage());
        } catch (InvocationTargetException e) {
            log.error(e.getMessage());
        }

    }

    public static <T> void setCreator(T data) {

        if (Objects.isNull(data)) {
            return;
        }

        try {
            BeanUtils.setProperty(data, CommonDict.CANDIDATE_NAME_CREATOR, SecurityService.currentUserName());
        } catch (IllegalAccessException e) {
            log.error(e.getMessage());
        } catch (InvocationTargetException e) {
            log.error(e.getMessage());
        }

    }


    /**
     * 记录更新者
     *
     * @param data
     * @param <T>
     */
    public static <T> void setUpdater(List<T> data) {

        if (Objects.isNull(data) || data.isEmpty()) {
            return;
        }

        try {

            for (T datum : data) {
                BeanUtils.setProperty(datum, CommonDict.CANDIDATE_NAME_UPDATER, SecurityService.currentUserName());
            }

        } catch (IllegalAccessException e) {
            log.error(e.getMessage());
        } catch (InvocationTargetException e) {
            log.error(e.getMessage());
        }

    }

    public static <T> void setUpdater(T data) {

        if (Objects.isNull(data)) {
            return;
        }

        try {
            BeanUtils.setProperty(data, CommonDict.CANDIDATE_NAME_UPDATER, SecurityService.currentUserName());
        } catch (IllegalAccessException e) {
            log.error(e.getMessage());
        } catch (InvocationTargetException e) {
            log.error(e.getMessage());
        }

    }


}
